package com.ruoyi.project.rest.trade.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.rest.trade.domain.RestMemberTrade;
import com.ruoyi.project.rest.trade.service.IRestMemberTradeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 交易纪录Controller
 * 
 * @author ruoyi
 * @date 2022-03-28
 */
@Controller
@RequestMapping("/rest/trade")
public class RestMemberTradeController extends BaseController
{
    private String prefix = "rest/trade";

    @Autowired
    private IRestMemberTradeService restMemberTradeService;

    @RequiresPermissions("rest:trade:view")
    @GetMapping()
    public String trade()
    {
        return prefix + "/trade";
    }

    /**
     * 查询交易纪录列表
     */
    @RequiresPermissions("rest:trade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RestMemberTrade restMemberTrade)
    {
        startPage();
        List<RestMemberTrade> list = restMemberTradeService.selectRestMemberTradeList(restMemberTrade);
        return getDataTable(list);
    }

    /**
     * 导出交易纪录列表
     */
    @RequiresPermissions("rest:trade:export")
    @Log(title = "交易纪录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RestMemberTrade restMemberTrade)
    {
        List<RestMemberTrade> list = restMemberTradeService.selectRestMemberTradeList(restMemberTrade);
        ExcelUtil<RestMemberTrade> util = new ExcelUtil<RestMemberTrade>(RestMemberTrade.class);
        return util.exportExcel(list, "交易纪录数据");
    }

    /**
     * 新增交易纪录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交易纪录
     */
    @RequiresPermissions("rest:trade:add")
    @Log(title = "交易纪录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RestMemberTrade restMemberTrade)
    {
        return toAjax(restMemberTradeService.insertRestMemberTrade(restMemberTrade));
    }

    /**
     * 修改交易纪录
     */
    @RequiresPermissions("rest:trade:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RestMemberTrade restMemberTrade = restMemberTradeService.selectRestMemberTradeById(id);
        mmap.put("restMemberTrade", restMemberTrade);
        return prefix + "/edit";
    }

    /**
     * 修改保存交易纪录
     */
    @RequiresPermissions("rest:trade:edit")
    @Log(title = "交易纪录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RestMemberTrade restMemberTrade)
    {
        return toAjax(restMemberTradeService.updateRestMemberTrade(restMemberTrade));
    }

    /**
     * 删除交易纪录
     */
    @RequiresPermissions("rest:trade:remove")
    @Log(title = "交易纪录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(restMemberTradeService.deleteRestMemberTradeByIds(ids));
    }
}
